package i18ntool.actions;

import i18ntool.consts.Constants;
import i18ntool.consts.Status;
import i18ntool.dialogs.AddI18ntoolDialog;
import i18ntool.entity.TreeNode;
import i18ntool.utils.NodeAssistant;
import iceworld.fernado.consts.Type;
import iceworld.fernado.entity.INode;

import java.util.logging.Logger;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

public class NewI18ntoolAction extends Action {
	public static final String ID = NewI18ntoolAction.class.getName();

	private static final Logger log = Logger.getLogger(ID);
	private TableViewer viewer;
	private IWorkbenchWindow window;
//	private INode[] nodes;
	private INode node;

	public NewI18ntoolAction(IWorkbenchWindow window, TableViewer viewer, INode node) {
		this.setText("New i18ntool");
		this.setToolTipText("New i18ntool");
		this.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
				.getImageDescriptor(Constants.I18NTOOL_IMG));
		this.viewer = viewer;
		this.window = window;
		this.node = node;
	}

	public void run() {
		ISelection selection = viewer.getSelection();
		Object obj = ((IStructuredSelection) selection).getFirstElement();
		AddI18ntoolDialog aid = new AddI18ntoolDialog(window.getShell());
		int code = aid.open();
		if (Window.OK == code) {
			node = new TreeNode(Constants.ROOT_KEY, Type.ROOT, Status.NORMAL);
			
			NodeAssistant.getInstance().addTreeNodeChangeListener(node);
		}
		aid.close();
	}
}
